﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="XsdMinOccursMaxOccursUnbounded", Namespace="http://kis.x-road.eu/", Target=typeof(XsdMinOccursMaxOccursUnbounded))]
    public class XsdMinOccursMaxOccursUnboundedSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected XsdMinOccursMaxOccursUnbounded clazz;
        
        public XsdMinOccursMaxOccursUnboundedSerializer(XsdMinOccursMaxOccursUnbounded clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (((clazz.BuiltInMin1MazUnboundedNil == null) 
                        || (clazz.BuiltInMin1MazUnboundedNil.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "BuiltIn_Min1_Maz_Unbounded_Nil");
            }
            for (int x = 0; ((clazz.BuiltInMin1MazUnboundedNil != null) 
                        && (x < clazz.BuiltInMin1MazUnboundedNil.Count)); x = (x + 1)) {
                Writer.WriteStartElement("BuiltIn_Min1_Maz_Unbounded_Nil");
                if (clazz.BuiltInMin1MazUnboundedNil[x]!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.BuiltInMin1MazUnboundedNil[x]))).ToString());
                }
                else {
                    Writer.WriteAttributeString("xsi", "nil", null, "1");
                }
                Writer.WriteEndElement();
            }
            if (((clazz.BuiltInMin1MazUnboundedNonNil == null) 
                        || (clazz.BuiltInMin1MazUnboundedNonNil.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "BuiltIn_Min1_Maz_Unbounded_NonNil");
            }
            for (int x = 0; ((clazz.BuiltInMin1MazUnboundedNonNil != null) 
                        && (x < clazz.BuiltInMin1MazUnboundedNonNil.Count)); x = (x + 1)) {
                Writer.WriteStartElement("BuiltIn_Min1_Maz_Unbounded_NonNil");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.BuiltInMin1MazUnboundedNonNil[x]))).ToString());
                Writer.WriteEndElement();
            }
            for (int x = 0; ((clazz.UdfMin0MazUnboundedNonNil != null) 
                        && (x < clazz.UdfMin0MazUnboundedNonNil.Count)); x = (x + 1)) {
                if (clazz.UdfMin0MazUnboundedNonNil[x]!=null) {
                    Writer.WriteStartElement("Udf_Min0_Maz_Unbounded_NonNil");
                    Writer.WriteString(clazz.UdfMin0MazUnboundedNonNil[x].ToString());
                    Writer.WriteEndElement();
                }
            }
            for (int x = 0; ((clazz.UdfMin0MazUnboundedNil != null) 
                        && (x < clazz.UdfMin0MazUnboundedNil.Count)); x = (x + 1)) {
                if (clazz.UdfMin0MazUnboundedNil[x]!=null) {
                    Writer.WriteStartElement("Udf_Min0_Maz_Unbounded_Nil");
                    Writer.WriteString(clazz.UdfMin0MazUnboundedNil[x].ToString());
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            clazz.BuiltInMin1MazUnboundedNil = new System.Collections.Generic.List<System.DateTime?>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "BuiltIn_Min1_Maz_Unbounded_Nil")); ) {
                if (Reader.LocalName=="BuiltIn_Min1_Maz_Unbounded_Nil") {
                    if ((Reader.IsElementNil() == false)) {
                        clazz.BuiltInMin1MazUnboundedNil.Add(new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("BuiltIn_Min1_Maz_Unbounded_Nil")).Value);
                    }
                    else {
                        clazz.BuiltInMin1MazUnboundedNil.Add(null);
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursUnbounded>BuiltIn_Min1_Maz_Unbounded_Nil", Reader.LocalName);
                }
            }
            if ((clazz.BuiltInMin1MazUnboundedNil.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "BuiltIn_Min1_Maz_Unbounded_Nil");
            }
            clazz.BuiltInMin1MazUnboundedNonNil = new System.Collections.Generic.List<System.DateTime>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "BuiltIn_Min1_Maz_Unbounded_NonNil")); ) {
                if (Reader.LocalName=="BuiltIn_Min1_Maz_Unbounded_NonNil") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursUnbounded>BuiltIn_Min1_Maz_Unbounded_NonNil");
                    }
                    clazz.BuiltInMin1MazUnboundedNonNil.Add(new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("BuiltIn_Min1_Maz_Unbounded_NonNil")).Value);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>XsdMinOccursMaxOccursUnbounded>BuiltIn_Min1_Maz_Unbounded_NonNil", Reader.LocalName);
                }
            }
            if ((clazz.BuiltInMin1MazUnboundedNonNil.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "BuiltIn_Min1_Maz_Unbounded_NonNil");
            }
            if (Reader.LocalName=="Udf_Min0_Maz_Unbounded_NonNil") {
                clazz.UdfMin0MazUnboundedNonNil = new System.Collections.Generic.List<global::Kis.Xroad.Eu.Gender>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "Udf_Min0_Maz_Unbounded_NonNil")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>XsdMinOccursMaxOccursUnbounded>Udf_Min0_Maz_Unbounded_NonNil");
                    }
                    clazz.UdfMin0MazUnboundedNonNil.Add(new global::Kis.Xroad.Eu.Gender(Reader.ReadElementString("Udf_Min0_Maz_Unbounded_NonNil")));
                }
            }
            if (Reader.LocalName=="Udf_Min0_Maz_Unbounded_Nil") {
                clazz.UdfMin0MazUnboundedNil = new System.Collections.Generic.List<global::Kis.Xroad.Eu.Gender>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "Udf_Min0_Maz_Unbounded_Nil")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        clazz.UdfMin0MazUnboundedNil.Add(new global::Kis.Xroad.Eu.Gender(Reader.ReadElementString("Udf_Min0_Maz_Unbounded_Nil")));
                    }
                    else {
                        clazz.UdfMin0MazUnboundedNil.Add(null);
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
